/**
 * Package	: com.coship.axis.services
 * File		: PositionBasicInfoServiceSkeleton.java
 * Company 	: Shenzhen Coship Electronics CO., LTD.
 * Version  : v1.0
 * Description 	: <Detail Description for package>
 *
 * Copyright (c) 2003-2009 Shenzhen Coship Electronics CO., LTD.
 * Rainbow Bldg.,North,Hi-Tech Industrial Park,Nanshan District,Shenzhen,China,P.C.518057.
 * All rights reserved.
 * The contents of this file are confidential and proprietary to COSHIP.
 * Copying is explicitly prohibited without the express permission of COSHIP.
 *
 * Create Date	: Apr 20, 2010
 * Create By    : 904120
 * History :$
 */
package com.coship.vasms.adstorm.webservice.position.positionbasicinfo;

import org.apache.commons.lang.StringUtils;

import com.coship.vasms.adstorm.common.BeanHelper;
import com.coship.vasms.adstorm.common.log.JLogger;
import com.coship.vasms.adstorm.common.log.LoggerFactory;
import com.coship.vasms.adstorm.service.PositionBasicInfoService;
import com.coship.vasms.adstorm.webservice.WebServiceConstant;
import com.coship.vasms.adstorm.webservice.WebServiceUtils;
import com.coship.vasms.adstorm.webservice.position.Response;
import com.coship.vasms.adstorm.webservice.position.positionbasicinfo.vo.PositionBasicInfoReq;
import com.coship.vasms.adstorm.webservice.position.positionbasicinfo.vo.PositionSize;

/**
 * 
 * File Name : PositionBasicInfoServiceSkeleton.java
 * 
 * @Description : 广告位基本信息webservice接口实现类
 * @author 904120
 */
public class PositionBasicInfoServiceSkeleton implements
		PositionBasicInfoServiceSkeletonInterface {
	private static JLogger logger = LoggerFactory
			.getLogger(PositionBasicInfoServiceSkeleton.class);
	private PositionBasicInfoService service = (PositionBasicInfoService) BeanHelper
			.getInstance().getBean("positionBasicInfoService");

	@Override
	public Response synPositionBasicInfo(PositionBasicInfoReq requset) {
		// TODO Auto-generated method stub
		Response resp = null;
		try {
			// 1.检查请求数据的完整性
			if (!checkReqData(requset)) {
				logger.debug("数据不完整,同步失败");
				resp = WebServiceUtils.buildResponse(
						WebServiceConstant.RESPONSE_ERROR_PARAMETER,
						"数据不完整,同步失败");
				return resp;
			}
			// 2.同步信息
			resp = service.synBasicInfo(requset);
		} catch (Exception e) {
			logger.debug("同步广告位基本信息失败,cause:", e);
			e.printStackTrace();
		}
		if (resp == null) {
			resp = WebServiceUtils.buildResponse(
					WebServiceConstant.RESPONSE_ERROR_SYSTEM, "系统发生异常");
		}
		return resp;
	}

	/**
	 * 
	 * Description : 检查请求数据的完整性
	 * 
	 * @param requset
	 * @return
	 * 
	 */
	private boolean checkReqData(PositionBasicInfoReq requset) {
		// 请求信息为空
		if (requset == null) {
			return false;
		}
		// 基本位信息编码
		if (StringUtils.isEmpty(requset.getPositionBasicCode())) {
			return false;
		}
		// 代理类型
		if (!WebServiceConstant.POSITION_ANGENTTYPE_VAS
				.equalsIgnoreCase(requset.getAgentType())) {
			return false;
		}

		// 广告位操作类型
		if (!WebServiceConstant.POSITIONBASICINFO_OP_ADD
				.equalsIgnoreCase(requset.getOperation())
				&& !WebServiceConstant.POSITIONBASICINFO_OP_DELETE
						.equalsIgnoreCase(requset.getOperation())
				&& !WebServiceConstant.POSITIONBASICINFO_OP_MODIFY
						.equalsIgnoreCase(requset.getOperation())) {
			return false;
		}
		// 如果是新增或者修改广告位基本信息，具体数据不能少
		if (WebServiceConstant.POSITIONBASICINFO_OP_ADD
				.equalsIgnoreCase(requset.getOperation())
				|| WebServiceConstant.POSITIONBASICINFO_OP_MODIFY
						.equalsIgnoreCase(requset.getOperation())) {
			// 名称
			if (StringUtils.isEmpty(requset.getName())) {
				return false;
			}
			// 广告类型：ContentType，不为空，1:文字、2:图片
			if (!WebServiceConstant.POSITIONBASICINFO_CONTENT_TYPE_C
					.equalsIgnoreCase(requset.getContentType())
					&& !WebServiceConstant.POSITIONBASICINFO_CONTENT_TYPE_P
							.equalsIgnoreCase(requset.getContentType())) {
				return false;
			}
			PositionSize positionSize = requset.getPositionSize();
			if (positionSize == null) {
				return false;
			}
			// 文字
			if (WebServiceConstant.POSITIONBASICINFO_CONTENT_TYPE_C
					.equalsIgnoreCase(requset.getContentType())) {
				if (StringUtils.isEmpty(positionSize.getCharacterSize())) {
					return false;
				}
			}
			// 图片
			if (WebServiceConstant.POSITIONBASICINFO_CONTENT_TYPE_P
					.equalsIgnoreCase(requset.getContentType())) {
				if (StringUtils.isEmpty(requset.getPositionSize()
						.getImageSize().getWidth())
						|| StringUtils.isEmpty(requset.getPositionSize()
								.getImageSize().getHight())) {
					return false;
				}
			}
		}
		// 新增广告基本位信息,需要对编码和名称的是否重复做检查
		/*
		 * if (WebServiceConstant.POSITIONBASICINFO_OP_ADD
		 * .equalsIgnoreCase(requset.getOperation())) { // 1.基本位信息:编码是否重复
		 * boolean existed = service.isExistPositionBasicCode(requset
		 * .getPositionBasicCode()); if (existed) { return false; } //
		 * 2.基本位信息:名称是否重复 existed =
		 * service.isExistPositionBasicCode(requset.getName()); if (existed) {
		 * return false; } }
		 */
		return true;
	}

}
